package com.baichang.taoshunda.controller;

import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IPageController;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.model.Page;
import com.baichang.taoshunda.ControllerConstants;
import com.baichang.taoshunda.service.WaiterTypeService;
import com.baichang.taoshunda.service.WaiterlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * Created by Administrator on 2018/2/8 0008.
 */
@Controller
@RequestMapping(ControllerConstants.WAITER)
public class WaiterServiceWController extends WebBaseController {

    @Autowired
    private WaiterTypeService waiterTypeService;

    @Autowired
    private WaiterlistService waiterlistService;


    /**
     * 跳转审核服务商家
     *
     * @return
     */
    @RequestMapping("/findAuditingBus")
    public String findAuditingBus() {
        return "taoshunda/auditing/waiterService";
    }

    /**
     * 查询需要审核的服务推广
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryAuditingBus")
    public void queryAuditingBus(final HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                String waiterName = getString(request, "waiterName", "");
                return waiterlistService.queryAuditingBus(waiterName, nowPage, pageSize);
            }
        });
    }

    /**
     * 查询本地服务商家类型
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryWaiterTypeId")
    public void queryWaiterTypeId(HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                return waiterTypeService.queryWaiterTypeId();
            }
        });
    }


    /**
     * 删除
     *
     * @param request
     * @param response
     */
    @RequestMapping("/updateWaiterStatus")
    public void updateWaiterStatus(final HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                Integer id = getInt(request, "id", 0);
                Integer status = getInt(request, "status", 0);
                return waiterlistService.updateStatus(id, status);
            }
        });
    }

    /**
     * 审核过的服务商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryWaiterBusiness")
    public void queryWaiterBusiness(final HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                String waiterName = getString(request, "waiterName", "");
                String address = getString(request, "address", "");
                Integer typeId = getInt(request, "typeId", 0);
                return waiterlistService.queryWaiterBusiness(waiterName, address, typeId, nowPage, pageSize);
            }
        });
    }

    /**
     * 通过审核
     *
     * @param request
     * @param response
     */
    @RequestMapping("/throughService")
    public void throughService(final HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                Integer id = getInt(request, "id", 0);
                Integer payTime = getInt(request, "payTime", 0);
                Integer starWaiter = getInt(request, "starWaiter", 0);
                return waiterlistService.throughService(id, payTime, starWaiter);
            }
        });
    }

    /**
     * @param request
     * @param response
     */
    @RequestMapping("/updateWaiterBusiness")
    public void updateWaiterBusiness(final HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServiceException {
                Integer id = getInt(request, "id", 0);
                String waiterName = getString(request, "waiterName", "");
                Integer waiterType = getInt(request, "waiterType", 0);
                BigDecimal price = BigDecimal.valueOf(getDouble(request, "price", 0)); //本地服务商家的价钱
                String listPic = getString(request, "listPic", "");
                String picture = getString(request, "picture", "");
                String remark = getString(request, "remark", "");
                Integer star = getInt(request, "star", 0);
//                String personalPic = getString(request, "personalPic", "");
//                String businessPic = getString(request, "businessPic", "");
                return waiterlistService.update(id, waiterName, waiterType, price, listPic, picture, remark, star);
            }
        });
    }
}
